#include<cstdio>
#include<vector>
using namespace std;
#define INF 0x7fffffff
class Road{
public:
    int distance;
    int cost;
    Road(int _distance, int _cost):distance(_distance),cost(_cost){}
};
int visited[500];
int cities[500];
int pre_city_indices[500];
int dist[500];
int cost[500];
Road* roads[500][500];
int n,m,s,d;
int main(){
    int i=0;
    scanf("%d %d %d %d",&n,&m,&s,&d);
    for(i=0;i<n;i++){
        for(int j=0;j<n;j++){
            Road* r=new Road(INF,INF);
            roads[i][j]=r;
            roads[j][i]=r;
        }
    }
    i=0;
    while(i<m){
        int c1,c2,di,co;
        scanf("%d %d %d %d",&c1,&c2,&di,&co);
        roads[c1][c2]->distance=di;
        roads[c1][c2]->cost=co;
        roads[c2][c1]->distance=di;
        roads[c2][c1]->cost=co;
        //printf("%d %d %d %d\n",c1,c2,di,co);
        i++;
    }
    for(i=0;i<n;i++){
        dist[i]=roads[s][i]->distance;
        cost[i]=roads[s][i]->cost;
        pre_city_indices[i]=(dist[i]==INF)?-1:s;
    }
    for(i=0;i<n;i++){
        int mindist=INF;
        int u=s;
        for(int j=0;j<n;j++){
            if(visited[j]==0&&dist[j]<mindist){
                u=j;
                mindist=dist[j];
            }
        }
        visited[u]=1;
        for(int j=0;j<n;j++){
            if(0==visited[j]&&roads[u][j]->distance<INF){
                if(dist[u]+roads[u][j]->distance<dist[j]){
                    dist[j]=dist[u]+roads[u][j]->distance;
                    pre_city_indices[j]=u;
                    cost[j]=cost[u]+roads[u][j]->cost;
                }else if(dist[u]+roads[u][j]->distance==dist[j]){
                    if(cost[u]+roads[u][j]->cost<cost[j]){
                        cost[j]=cost[u]+roads[u][j]->cost;
                        pre_city_indices[j]=u;
                    }
                }
            }
        }
    }
    //for(i=0;i<n;i++){
    //    for(int j=0;j<n;j++){
    //        printf("%d ",roads[i][j]->distance);
    //    }
    //    printf("\n");
    //}

    //for(i=0;i<n;i++){
    //    printf("%d ",pre_city_indices[i]);
    //}
    //printf("\n");
    vector<int> res;
    res.push_back(d);
    int tmp=pre_city_indices[d];
    while(tmp!=s){
        res.push_back(tmp);
        tmp=pre_city_indices[tmp];
    }
    res.push_back(s);
    printf("%d",res[res.size()-1]);
    for(i=res.size()-2;i>=0;i--){
        printf(" %d",res[i]);
    }
    printf(" %d %d",dist[d],cost[d]);
    return 0;
}
